#include "stdafx.h"
#include "TestPDMSPerObjManager.h"
#include "PDMSPerObjManager.h"
#include "Treetest.h"
#include "Hash.h"

using namespace PDMS::PDMSFrame;

CPPUNIT_TEST_SUITE_REGISTRATION( TestPDMSPerObjManager );


TestPDMSPerObjManager::TestPDMSPerObjManager()
{
}


TestPDMSPerObjManager::~TestPDMSPerObjManager()
{
}

void TestPDMSPerObjManager::TestTreeModel()
{
	PDMS::PDMSFrame::PDMSPerObjManager manager;
	PDMS::PDMSFrame::Tree* pTree = NULL;

	UESoft::ErrorStatus es = manager.TreeModel( pTree );
	CPPUNIT_ASSERT( es == UESoft::eOk );
	CPPUNIT_ASSERT( pTree != NULL );
	CPPUNIT_ASSERT( pTree->HashModel() != NULL );
	pTree->Close();
}

void TestPDMSPerObjManager::TestHashModel()
{
	PDMS::PDMSFrame::PDMSPerObjManager manager;
	PDMS::PDMSFrame::Hash* pPOM = NULL;

	pPOM = manager.HashModel();
	CPPUNIT_ASSERT( pPOM );
}

void TestPDMSPerObjManager::TestRemoveAll()
{
	PDMS::PDMSFrame::PDMSPerObjManager manager;
	Tree* pRootTree = NULL;
	UESoft::ErrorStatus es = manager.TreeModel( pRootTree );
	CPPUNIT_ASSERT( es == UESoft::eOk );

	PDMS::PDMSFrame::Tree* pTree = new TreeTest;
	CPPUNIT_ASSERT( pTree->Id().IsNull() );

	pRootTree->Add( pTree );
	CPPUNIT_ASSERT( !pTree->Id().IsNull() );
	CPPUNIT_ASSERT( pRootTree->SubTreeCount() == 1 );
	CPPUNIT_ASSERT( manager.HashModel()->Size() == 2 );
	pTree->Close();
	
	pRootTree->Close();
	manager.RemoveAll();
	CPPUNIT_ASSERT( manager.HashModel()->Size() == 0 );

}

void TestPDMSPerObjManager::TestGenerateID()
{
	PDMSPerObjManager config;
	
	UeObjectId id = config.GenerateId();
	CPPUNIT_ASSERT( !id.IsNull() );
	
	id = config.GenerateId();
	CPPUNIT_ASSERT( !id.IsNull() );
}
